package beans;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class DBConnection {
	static final String url ="jdbc:mysql://localhost:3306/test?autoReconnect=true";
	static final String user="root";
	static final String pass="root";
	private static ComboPooledDataSource dataSource = null;
	
	public static ComboPooledDataSource getDataSource() {
		if(dataSource==null)
			getConn();
		return dataSource;
	}
	
	private static void getConn(){
		try{
			dataSource = new ComboPooledDataSource();
			dataSource.setDriverClass("com.mysql.jdbc.Driver");
			dataSource.setJdbcUrl(url);
			dataSource.setUser(user);
			dataSource.setPassword(pass);
			System.out.println("Connessione al database effettuata!");
		} catch (Exception e){
			e.printStackTrace();
		}
	}
}
